<template>
  <div class="logo">
    <div >
      <el-form ref="loginForm" :model="userObj" :rules="rules" label-width="80px" class="login-box">
        <h3 class="login-title">欢迎登录</h3>
        <el-form-item label="账号" prop="name">
          <el-input type="text" placeholder="请输入账号" v-model="userObj.name"/>
        </el-form-item>
        <el-form-item label="密码" prop="pwd">
          <el-input type="password" placeholder="请输入密码" v-model="userObj.pwd"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit()">登录</el-button>
        </el-form-item>
      </el-form>
      <vue-particles
          color="#3B5780"
          :particleOpacity="0.7"
          :particlesNumber="80"
          shapeType="circle"
          :particleSize="4"
          linesColor="#000"
          :linesWidth="1"
          :lineLinked="true"
          :lineOpacity="0.4"
          :linesDistance="80"
          :moveSpeed="2"
          :hoverEffect="true"
          hoverMode="grab"
          :clickEffect="false"
          clickMode="bubble"
      >
      </vue-particles>

    </div>
  </div>
</template>

<script>
import axios from "axios"
export default {
  data() {
    return {
      // 表单验证，需要在 el-form-item 元素中增加 prop 属性
      rules: {
        name: [
          {required: true, message: '账号不可为空', trigger: 'blur'}
        ],
        pwd: [
          {required: true, message: '密码不可为空', trigger: 'blur'}
        ]
      },
      userObj:{},
    }
  },
  methods: {
    onSubmit() {
      // 为表单绑定验证功能
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          axios.get("/project/sale/login",{
            params:{
              userName:this.userObj.name,
              pwd:this.userObj.pwd
            }
          }).then(
              resp=>{
                if(resp.data==""){
                  this.$message({
                    type:'error',
                    message:'登陆失败'
                  })

                }else {
                  sessionStorage.setItem("loginUser",JSON.stringify(resp.data));

                  this.$router.push('/index');
                }
              }
          )
        }
      });
    }
  }
}
</script>

<style  scoped>
.logo{
  width: 1290px;
  height: 629px;
  background: #F7941E;  /* fallback for old browsers */
  background: -webkit-linear-gradient(to right, #00A651, #72C6EF, #F7941E);  /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to right, #00A651, #72C6EF, #F7941E); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  background-size: cover;
  position: relative;
}
.login-box {
  border: 1px solid #DCDFE6;
  width: 350px;
  margin: 180px auto;
  padding: 35px 35px 15px 35px;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  box-shadow: 0 0 25px #909399;
  position: absolute;
  left: 400px;
  top: 0px;
}

.login-title {
  text-align: center;
  margin: 0 auto 40px auto;
  color: #303133;
}
</style>


